package com.shanshan.crowd.mvc.config;

import com.shanshan.crowd.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;
import java.util.List;

/**
 * @Description 考虑到 User 对象中仅仅包含账号和密码，为了能够获取到原始的 Admin 对象，专门创建这个类对 User类进行扩展
 * @ClassName SecurityAdmin
 * @Author 山山大魔王
 * @Date 2022/7/26 20:29
 * @Version 1.0
 */
public class SecurityAdmin extends User {

    private static final long serialVersionUID = 1L;

    private Admin originalAdmin;

    public SecurityAdmin(Admin originalAdmin, List<GrantedAuthority> authorities){

        super(originalAdmin.getLoginAcct(),originalAdmin.getUserPswd(),authorities);

        // 给本类的 this.originalAdmin 赋
        this.originalAdmin = originalAdmin;

        // 将原始 Admin 对象中的密码擦除
        this.originalAdmin.setUserPswd(null);
    }

    public Admin getOriginalAdmin() {
        return originalAdmin;
    }
}
